package com.aacar.controller.homepage;

import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.aacar.controller.ValidController;
import com.aacar.dto.Header;
import com.aacar.service.BannerService;
import com.aacar.utils.ResultInfoUtil;
import com.aacar.vo.BannerVo;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Maps;

/**
 * 获取banner广告位
 * @author 王辉
 *
 */
@RestController
@RequestMapping("/banner")
public class BannerController extends ValidController{
	
	private Logger logger = LoggerFactory.getLogger(this.getClass());
	
	@Autowired
	private BannerService bannerService;
	
	/**
	 * 获取首页banner广告位
	 * @return
	 */
	@RequestMapping(value = "/getHomePageBanner/0", method = RequestMethod.POST)
    @ResponseBody
	public Object getHomePageBanner(@RequestHeader(value="mobilehead") String mobilehead) {
		logger.info("request:/banner/getHomePageBanner/0");
		Header header = null;
    	if(null != mobilehead) {
    		header = JSON.parseObject(mobilehead, Header.class);
    	}
		List<BannerVo> banners = this.bannerService.getHomeBanner();
		Map<String,Object> m = Maps.newConcurrentMap();
		m.put("banners", banners);
		return ResultInfoUtil.setSuccessInfo(m,header.getService());
	}
}
